const enterpriseVue = new Vue({
  el: '#app',
  data() {
    return {
      pickerOptions: pickerOptions,
      rules: {
        Trading_Detail_Name: [{
          required: true,
          message: '请输入付款周期',
          trigger: 'blur',
        }],
      },
      form: {
        Trading_Detail_SerialNumber: "",
        Trading_Detail_Name: '',
      },
      loading: false
    }
  },
  mounted() {
    const Trading_Detail_SerialNumber = sessionStorage.getItem("Trading_Detail_SerialNumber")
    this.getData(Trading_Detail_SerialNumber)
  },
  methods: {
    getData(Trading_Detail_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/getInquiryIDOriginal?token=' + $.cookie('token'),
        type: 'GET',
        data: { 
          Data: 'trading_detail',
          Primary_Key_Name: 'Trading_Detail_SerialNumber',
          Primary_Key: Trading_Detail_SerialNumber
        },
        success: function (res) {
          _this.form = res[0]
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.loading = true
          $.ajax({
            url: DomainName + '/getEditAction?token='+$.cookie('token'),
            type: 'POST',
            data:{ Data: JSON.stringify({ Modify: { trading_detail: [_this.form] } }) },
            success: function (res) {
              console.log('提交结果', res)
              _this.$message.success("提交成功")
              window.history.go(-1);
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    deal() {
      const modify = deepClone(this.form)
      return { add: null, modify };
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
})